<?php
$a=getVar('a');
includeLang('config');
switch($a)
{
    case 'upd':
        $qry=$sql->query("SELECT name, config.type as type_id, config_type.type as type_name, value FROM config , config_type WHERE config.type =  id;");
        while ( $row = $sql->fetch_array($qry) )
        {
            $type =getVar($row['type_id'].'_'.$row['name'].'_t');
            $value=getVar($row['type_id'].'_'.$row['name'].'_v');
            $sql->query("UPDATE `config` SET `type`='$type', `value` = '$value' WHERE `name` = '{$row['name']}' AND `type`='{$row['type_id']}'");
            $item=$Lang[$row['type_name']].'->'.$Lang[$row['type_name'].'_'.$row['name']]['name'].' ';
            if($sql->row_count)
                msg($Lang['success'],$item.$Lang['success_update']);
            else
                msg($Lang['warning'],$item.$Lang['failed_to_update_or'], 'warning');
        }
    break;
    default:
            ?>
            <form action="?p=<?php echo $page;?>&a=upd" method="post">
            <table border="1"><?php
            $types=array();
            $tqry=$sql->query("SELECT * FROM config_type");
            while($type=$sql->fetch_array($tqry))
            {
                array_push($types, $type);
            }
            $qry=$sql->query("SELECT name, config.type as type_id, config_type.type as type_name, value FROM config , config_type WHERE config.type =  id;");
            while ( $row = $sql->fetch_array($qry) )
            {?>
                <tr title="<?php echo $Lang[$row['type_name'].'_'.$row['name']]['title'];?>">
                <td><?php echo $Lang[$row['type_name'].'_'.$row['name']]['name'];?>:</td>
                <td><select name="<?php echo $row['type_id'].'_'.$row['name'];?>_t">
                <?php
                foreach($types as $type)
                {
                    $sel=$row['type_id']==$type['id']?' selected="selected"':'';
                    echo '<option value="'.$type['id'].'"'.$sel.'>'.$Lang[$type['type']].'</option>';
                }
                ?>
                </select></td>
                <td><input name="<?php echo $row['type_id'].'_'.$row['name'];?>_v" size="50" value="<?php echo htmlspecialchars(stripslashes($row['value']));?>" type="text" /></td>
                </tr>
      <?php }?>
            
            </table><input value="<?php echo $Lang['save'];?>" type="submit" />
            </form><?php
    break;
}

?>